package hu.arguscab.ai.util;

import static org.lwjgl.opengl.GL11.GL_QUADS;
import static org.lwjgl.opengl.GL11.glVertex2i;
import hu.arguscab.graphic.DrawablePrimitive;

public class Rect extends DrawablePrimitive {
	private int x2, y2;
	private int w, h;
	
	public Rect() {
	}
	
	public Rect(int x, int y, int w, int h) {
		setX(x);
		setY(y);
		this.w = w;
		this.h = h;
		refreshX2();
		refreshY2();
	}
	
	@Override
	public int getGLType() {
		return GL_QUADS;
	}

	@Override
	public void drawImpl() {
		glVertex2i(0, 0);
		glVertex2i(w, 0);
		glVertex2i(w, h);
		glVertex2i(0, h);
	}
	
	
	public void setX(int x) {
		super.setX(x);
		refreshX2();
	}
	public void setY(int y) {
		super.setY(y); 
		refreshY2();
	}
	public int getW() {
		return w;
	}
	public void setW(int w) {
		this.w = w;
		refreshX2();
	}
	public int getH() {
		return h;
	}
	public void setH(int h) {
		this.h = h;
		refreshY2();
	}
	
	public int getX2() {
		return x2;
	}

	public void setX2(int x2) {
		this.x2 = x2;
		refreshX();
	}

	public int getY2() {
		return y2;
	}

	public void setY2(int y2) {
		this.y2 = y2;
		refreshY();
	}
	
	@Override
	public String toString() {
		return "x: "+getX()+", y: "+getY()+", w: "+w+", h: "+h;
	}

	private void refreshX2() {
		x2 = getX() + w;
	}
	
	private void refreshY2() {
		y2 = getY() + h;
	}
	
	private void refreshX() {
		setX(x2 - w);
	}
	
	private void refreshY() {
		setY(y2 - h);
	}
}
